/** @type {import('next').NextConfig} */
const nextConfig = {
    webpack: (config, { isServer }) => {
        config.module.rules.push({
            test: /\.LICENSE$/,
            use: 'null-loader'
        });

        config.module.rules.push({
            test: /\.node$/,
            use: 'null-loader'
        });

        config.resolve.alias = {
            ...config.resolve.alias,
            '@umijs/bundler-webpack/compiled/copy-webpack-plugin/LICENSE': false,
            '@umijs/bundler-webpack/compiled/copy-webpack-plugin': false,
            '@umijs/es-module-parser-win32-x64-msvc': false,
            '@umijs/max': false,
            '@umijs/openapi': false
        };

        return config;
    },
    transpilePackages: ['@ant-design/pro-components', '@ant-design/plots', 'antd-style'],
    experimental: {
        serverActions: true
    },
    async headers() {
        return [
            {
                source: '/api/:path*',
                headers: [
                    { key: 'Access-Control-Allow-Credentials', value: 'true' },
                    { key: 'Access-Control-Allow-Origin', value: '*' },
                    { key: 'Access-Control-Allow-Methods', value: 'GET,DELETE,PATCH,POST,PUT' },
                    { key: 'Access-Control-Allow-Headers', value: 'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version' },
                    { key: 'Cache-Control', value: 'no-store, no-cache, must-revalidate, proxy-revalidate' },
                    { key: 'Pragma', value: 'no-cache' },
                    { key: 'Expires', value: '0' },
                ]
            }
        ]
    },
    // 跨域问题
    async rewrites() {
        return [
            {
                source: '/api/:path*',
                destination: 'http://localhost:8080/api/:path*'
            }
        ]
    },

    // 根路径重定向到/mood, todo
    async redirects() {
        return [
            {
                source: '/',
                destination: '/mood',
                permanent: true,
            },
        ]
    }
};

export default nextConfig;
